package logic

import (
	"camera/C/Rpc/model/mysql"
	"context"
	"fmt"

	"camera/C/Rpc/camera"
	"camera/C/Rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 列表展示
func (l *ListLogic) List(in *camera.ListRequest) (*camera.ListResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Good{}
	good, err := g.GetGood(int(in.Page), int(in.PageSize))
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}
	var list []*camera.ListItem
	for _, g2 := range good {
		list = append(list, &camera.ListItem{
			UserId:    int64(g2.UserId),
			GoodTitle: g2.GoodTitle,
			GoodStock: int64(g2.GoodStock),
			GoodImage: g2.GoodImage,
			GoodPrice: float32(g2.GoodPrice),
			GoodLike:  int64(g2.GoodLike),
			Id:        int64(g2.ID),
		})
	}
	return &camera.ListResponse{
		List: list,
	}, nil
}
